// import { parseTimeMixed } from '@/filters'
export const REF_TABLE = 'gridTable'
export const USER_CONFIG = {
  ref: REF_TABLE,
  gridConfig: [
    {
      label: 'SPUID',
      prop: 'id',
      width: 80,
      resizable: false
    },
    {
      label: '商品',
      prop: 'name',
      className: 'table-media-column',
      resizable: false,
      width: 250,
      showOverflowTooltip: false,
      render: (h, scope) => {
        return [
          h('em-image', {
            props: {
              src: scope.row.thumb,
              width: '54',
              radius: '5'
            }
          }),
          h(
            'span',
            {
              attrs: {
                class: 'media-body em-multi-ellipsis--l2'
              }
            },
            scope.row.title
          )
        ]
      }
    },
    {
      label: '提点比例',
      prop: 'balanceRates',
      className: 'table-media-column',
      resizable: false,
      render: (h, scope) => {
        return scope.row.balanceRates.map(item => {
          return h('span', {}, item)
        })
      }
    },
    {
      label: '价格（元）',
      prop: 'price',
      resizable: false,
      align: 'right'
    },
    {
      label: '规格数',
      prop: 'specCount',
      resizable: false,
      align: 'right',
      render: (h, params, ctx) => {
        var specCount = params.row.specCount
        if (specCount > 1) {
          return h(
            'el-badge',
            {
              props: {
                value: specCount,
                type: 'primary'
              }
            },
            [
              h(
                'el-button',
                {
                  props: {
                    size: 'mini',
                    type: 'text'
                  },
                  on: {
                    click: () => {
                      const $table = ctx.parent.$refs[REF_TABLE]
                      $table.toggleRowExpansion(params.row)
                    }
                  }
                },
                '多规格'
              )
            ]
          )
        } else {
          return h(
            'el-tag',
            {
              props: {
                size: 'mini',
                type: 'success'
              }
            },
            '单品'
          )
        }
      }
    },
    {
      type: 'expand',
      width: 1,
      className: 'expand-column',
      render: (h, scope) => {
        var skus = scope.row.skus
        var raw = []
        for (var i = 0, size = skus.length; i < size; i++) {
          var goods = skus[i]
          var template = h('em-goods-card', {
            attrs: {
              title: goods.name,
              thumb: goods.thumb
            },
            scopedSlots: {
              desc: () =>
                h(
                  'div',
                  {
                    attrs: {
                      class: 'kvlist'
                    }
                  },
                  [
                    h('dl', {}, [h('dt', {}, '价格：'), h('dd', {}, goods.price)]),
                    h('dl', {}, [h('dt', {}, '销量：'), h('dd', {}, goods.sales)]),
                    h('dl', {}, [h('dt', {}, '库存：'), h('dd', {}, goods.stock)])
                  ]
                )
            }
          })
          raw.push(template)
        }
        return h(
          'div',
          {
            attrs: {
              class: 'goods-grid'
            }
          },
          raw
        )
      }
    },
    {
      label: '点击量',
      prop: 'stats',
      align: 'right',
      render: (h, params) => {
        var stats = params.row.stats
        return (
          stats &&
          h(
            'el-tag',
            {
              props: {
                size: 'mini',
                type: 'warning'
              }
            },
            stats.views
          )
        )
      }
    },
    {
      label: '状态',
      prop: 'status',
      align: 'right',
      render: (h, params) => {
        if (params.row.status === 10) {
          return h(
            'el-tag',
            {
              props: {
                size: 'mini',
                type: 'success'
              }
            },
            '售卖中'
          )
        } else {
          return h(
            'el-tag',
            {
              props: {
                size: 'mini',
                type: 'warning'
              }
            },
            '未上架'
          )
        }
      }
    },
    {
      label: '更新时间',
      prop: 'updated_at',
      align: 'right',
      format: {
        type: 'rowtime'
      }
    }
  ],
  // crud的模态框表单配置，可配置表单类型，验证规则，是否必填,col-span布局可通过span参数配置
  filterConfig: [
    {
      label: '商品名称/货号/关键字',
      prop: 'keyword',
      type: 'text'
    },
    {
      label: '库存数量',
      prop: 'oos',
      type: 'select',
      multiple: false,
      data: [
        {
          name: '缺货',
          id: 1
        },
        {
          name: '正常',
          id: 0
        }
      ]
    },
    {
      label: '发售状态',
      prop: 'shelves',
      type: 'select',
      multiple: false,
      data: [
        {
          name: '上架',
          id: 10
        },
        {
          name: '下架',
          id: 0
        }
      ]
    },
    {
      label: '类型',
      prop: 'recommend',
      type: 'select',
      multiple: false,
      data: [
        {
          name: '新品',
          id: 1
        },
        {
          name: '热门',
          id: 2
        },
        {
          name: '推荐',
          id: 3
        },
        {
          name: '热销',
          id: 4
        }
      ]
    }
  ],
  // crud的操作按钮配置，基础按钮有添加、修改、删除、查看，还可以配置扩展按钮
  gridHandles: [
    {
      name: '预览',
      emitName: 'view'
    },
    {
      name: '修改',
      emitName: 'update'
    }
  ]
}
